Skip to content

ROX-35081: Add instance report admin command - #2764

Open
kovayur wants to merge 3 commits into
mainfrom
yury/ROX-35081-instance-report
Open

ROX-35081: Add instance report admin command#2764
kovayur wants to merge 3 commits into
mainfrom
yury/ROX-35081-instance-report

Conversation

@kovayur

@kovayur kovayur commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR summary

Adds the fleet-manager admin central report command, which retrieves all Centrals through the Fleet Manager admin API and reports instance counts by cloud provider, region, plan, and status.

The PR also:

  • Moves the admin subcommand from acsfleetctl to fleet-manager.
  • Refactors fleet-manager startup handling with rootCommand() and explicit exit codes.
  • Refactors fleetmanagerclient to use functional options and support RHSSO authentication.
  • Adds the expired_at field to the admin Central model and OpenAPI specification.
  • Adds unit tests for the report command.

This is part one of two; a follow-up will add a scheduled Tekton pipeline that posts report results to Slack.

Comments summary

The PR author requested a review from CodeRabbit. The automated review was not completed because the review service was rate limited.

Commit messages summary

A pagination fix prevents fetchAllCentrals from looping indefinitely when the API returns an empty page. Another commit removes the probe client.


The following was generated by @coderabbitai and may be updated automatically.

Summary

  • Added fleet-manager admin central report.
  • Added paginated Central retrieval with filtering for probe, failed, expired, evaluation, and regional instances.
  • Added Slack-compatible report sections and formatting fallbacks for organization, quota, expiration, and failure data.
  • Added unit tests for report formatting, filtering, and section rendering.
  • Moved the admin command from acsfleetctl to fleet-manager.
  • Refactored command startup, context-based client access, authentication setup, and explicit exit handling.
  • Added organisation_name to the admin Central model, presenters, and OpenAPI schemas.
  • Removed the obsolete probe Fleet Manager client factory.

Checklist (Definition of Done)

  • Unit and integration tests added
  • Documentation added if necessary (i.e. changes to dev setup, test execution, ...)
  • Discussed security and business related topics privately
  • CI and all relevant tests are passing

Test manual

  1. Configure Fleet Manager API credentials and the API URL.
  2. Run fleet-manager admin central report.
  3. Verify that the output contains the expected regional, evaluation, expired, and failed sections.
  4. Verify that probe instances do not appear in the main report.
  5. Verify that pagination completes when the API returns an empty page.
  6. Run the relevant unit tests for internal/central/pkg/cmd/admin/centrals.

Add `fleet-manager admin central report` command that fetches all
centrals from the fleet-manager API and generates a summary report.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kovayur

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved label Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds the admin command to fleet-manager, removes it from acsfleetctl, centralizes Fleet Manager client authentication, adds central reporting, and exposes organisation name data in admin API models and schemas.

Changes

Admin central reporting

Layer / File(s) Summary
Central data contract
internal/central/pkg/api/admin/private/..., internal/central/pkg/presenters/admin_central.go, openapi/fleet-manager-private-admin.yaml
Admin Central responses now include organisation name, organisation ID, and quota type fields.
Admin client authentication
internal/central/pkg/cmd/admin/cmd.go, internal/central/pkg/cmd/fleetmanagerclient/client.go
The admin command creates an authenticated Fleet Manager client from configurable flags and environment variables, then stores it in command context.
Central report command
internal/central/pkg/cmd/admin/centrals/*
The new report command fetches, filters, groups, and formats central instances into Slack-compatible sections. Tests cover formatting, filtering, fallbacks, and alignment.
CLI command wiring
cmd/fleet-manager/main.go, cmd/acsfleetctl/main.go
fleet-manager registers the admin command. acsfleetctl no longer registers it. Initialization and execution errors now print to stderr and exit explicitly.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AdminCLI
  participant AdminCommand
  participant FleetManagerClient
  participant FleetManagerAPI
  participant ReportWriter
  AdminCLI->>AdminCommand: Execute central report
  AdminCommand->>FleetManagerClient: Create and retrieve authenticated client
  AdminCommand->>FleetManagerAPI: Fetch paginated central instances
  FleetManagerAPI-->>AdminCommand: Return central records
  AdminCommand->>ReportWriter: Filter, group, and format records
  ReportWriter-->>AdminCLI: Write Slack-compatible report
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the addition of the instance report admin command, which is the primary change.
Description check ✅ Passed The description is empty, but the repository template explicitly permits an empty description.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yury/ROX-35081-instance-report

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/central/pkg/api/admin/private/model_central.go`:
- Around line 28-47: Keep the organisation_name field defined in the canonical
OpenAPI specification rather than editing model_central.go directly, then run
make generate and commit the regenerated output. Ensure the generated Central
model retains the organisation_name JSON property.

In `@internal/central/pkg/cmd/admin/centrals/report.go`:
- Around line 94-150: Extend the report generation around the existing
allCentrals classification loop and writeSection calls to aggregate and print
counts by cloud provider, region, plan, and status for all relevant centrals,
rather than only the current recent-region, eval, expiration, and failed tables.
Reuse the central fields and established report formatting helpers, ensure probe
instances follow the existing exclusion behavior, and add tests covering each
aggregate’s counts before release.
- Around line 52-70: Update the pagination loop around api.GetCentrals to return
an error when list.Items is empty while the fetched count is still below
list.Total, preventing further page requests. Compare the counts using a
non-narrowing type instead of converting len(all) to int32, while preserving the
existing completion condition and error context.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ae94c87-d189-44ae-9fb3-a4e6b55eda72

📥 Commits

Reviewing files that changed from the base of the PR and between 877dd26 and fcad766.

📒 Files selected for processing (12)
  • cmd/acsfleetctl/main.go
  • cmd/fleet-manager/main.go
  • internal/central/pkg/api/admin/private/api/openapi.yaml
  • internal/central/pkg/api/admin/private/model_central.go
  • internal/central/pkg/cmd/admin/centrals/cmd.go
  • internal/central/pkg/cmd/admin/centrals/list.go
  • internal/central/pkg/cmd/admin/centrals/report.go
  • internal/central/pkg/cmd/admin/centrals/report_test.go
  • internal/central/pkg/cmd/admin/cmd.go
  • internal/central/pkg/cmd/fleetmanagerclient/client.go
  • internal/central/pkg/presenters/admin_central.go
  • openapi/fleet-manager-private-admin.yaml
💤 Files with no reviewable changes (1)
  • cmd/acsfleetctl/main.go

Comment thread internal/central/pkg/api/admin/private/model_central.go
Comment thread internal/central/pkg/cmd/admin/centrals/report.go
Comment thread internal/central/pkg/cmd/admin/centrals/report.go
The pagination loop in fetchAllCentrals only terminated when the
accumulated count reached list.Total, which could spin forever if the
API returned an empty Items slice. Break early on empty pages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kovayur

kovayur commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

if err != nil {
glog.Fatalf("Failed to create connection: %s", err)
return
_, _ = fmt.Fprintf(os.Stderr, "Failed to create connection: %s\n", err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid printing stacktrace (glog.Fatalf behavior)

@openshift-ci

openshift-ci Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@kovayur: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e 0075ddc link true /test e2e

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant